package com.eatrip.dao.implementation;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.eatrip.bean.FasciaPrezzo;
import com.eatrip.dao.FasciaPrezziDAO;

@Repository
@Transactional
public class FasciaPrezziDAOImple implements FasciaPrezziDAO{
	
	private HibernateTemplate hibernateTemplate;
	
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		hibernateTemplate = new HibernateTemplate(sessionFactory);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public FasciaPrezzo getFasciaPrezzi(int id) {
		List<FasciaPrezzo> list = hibernateTemplate.find("FROM FasciaPrezzo WHERE idFasciaPrezzo = ?",id);
		if (list.size() == 0)
			return null;
		return list.get(0);
	}

	@Override
	public void insertFasciaPrezzo(FasciaPrezzo fasciaPrezzo) {
		hibernateTemplate.save(fasciaPrezzo);
	}

}
